 package com.zu.commu.auto1_0.protocol.pump;

 import com.zu.commu.auto1_0.DataType1_0;
    import com.zu.commu.auto1_0.protocol.CheckData;
    import com.zu.commu.auto1_0.protocol.Util;
    import com.zu.commu.exception.CommuException;

 public class SetPumpProtocol
 {
   public byte[] remoteData(String meterNo, String order)
     throws Exception
   {
     String temp = "";
     try {
       temp = checkValue(order);
     } catch (Exception e) {
       throw e;
     }

     byte[] buf = new byte[15];
     buf[0] = 104;
     buf[1] = 9;
     buf[2] = 9;
     buf[3] = 104;
     Util u = new Util();
     try {
       byte[] b = u.hex2Byte(meterNo);
       for (int i = 0; i < b.length; i++)
         buf[(4 + i)] = b[i];
     }
     catch (Exception e) {
       throw new CommuException().setMessage(
         "测控器地址号不合法！" + e.getMessage(), null);
     }
     buf[10] = 64;
     buf[11] = (byte)DataType1_0.PUMP.toInt();

     if (temp.equals("start")) {
       buf[12] = -52;
     }
     if (temp.equals("stop")) {
       buf[12] = 85;
     }

     buf[13] = new CheckData().getCrcCheck(buf, 4, 12);
     buf[14] = 22;
     return buf;
   }

   public String checkValue(String value)
     throws CommuException
   {
     if ((value == null) || (value.equals(""))) {
       throw new CommuException().setMessage("操作水泵命令不合法！", null);
     }
     if ((!value.equals("start")) && (!value.equals("stop"))) {
       throw new CommuException().setMessage("操作水泵命令不合法！", null);
     }
     return value;
   }
 }
